package pkg

import (
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"log"
)

func UploadOssFile(address, name string) string {
	client, err := oss.New("https://oss-cn-shanghai.aliyuncs.com", "LTAI5tA9AjMxf3RqU9qzP4gB", "fqzGDkKQUROeTAYq3uzqe04k49H9eF")
	if err != nil {
		log.Fatalf("Failed to create OSS client: %v", err)
	}
	// 填写存储空间名称，例如examplebucket。
	bucketName := "2206axxz" // 请替换为实际的Bucket名称
	bucket, err := client.Bucket(bucketName)
	if err != nil {
		log.Fatalf("Failed to get bucket: %v", err)
	}

	// 依次填写Object的完整路径（例如exampledir/exampleobject.txt）和本地文件的完整路径（例如D:\\localpath\\examplefile.txt）。
	objectKey := "exampledir/" + name // 请替换为实际的对象Key
	localFilePath := address          // 请替换为实际的本地文件路径
	err = bucket.PutObjectFromFile(objectKey, localFilePath)
	if err != nil {
		log.Fatalf("Failed to put object from file: %v", err)
	}
	log.Println("File uploaded successfully.")
	url := ""
	return url

}
